//
//  SearchLeftImageTextField.m
//  江淮卡友
//
//  Created by 杜文杰 on 2021/1/27.
//

#import "SearchLeftImageTextField.h"

@implementation SearchLeftImageTextField

- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        // 左边的view 放大镜显示
        self.leftViewMode = UITextFieldViewModeAlways;
        // 自带清除按钮
        self.clearButtonMode = UITextFieldViewModeWhileEditing;
        // 边框样式 可以去掉自己添加边框
//        self.borderStyle = UITextBorderStyleNone;
    }
    return self;
}

// 左边的放大镜 距离左边位置
- (CGRect)leftViewRectForBounds:(CGRect)bounds {
    CGRect iconRect = [super leftViewRectForBounds:bounds];
    iconRect.origin.x += kRealValue(10);// 右偏10
    return iconRect;
}

//控制清除按钮的位置
- (CGRect)clearButtonRectForBounds:(CGRect)bounds {
    return CGRectMake(bounds.origin.x + bounds.size.width - 40, bounds.origin.y, bounds.size.height, bounds.size.height);
}

//显示文本位置
- (CGRect)textRectForBounds:(CGRect)bounds {
    CGRect inset = CGRectMake(bounds.origin.x + kRealValue(36), bounds.origin.y, bounds.size.width - kRealValue(70), bounds.size.height);//更好理解些
    return inset;
}

//编辑时文本位置
- (CGRect)editingRectForBounds:(CGRect)bounds {
    CGRect inset = CGRectMake(bounds.origin.x + kRealValue(36), bounds.origin.y, bounds.size.width - kRealValue(70), bounds.size.height);
    return inset;
}

@end
